'''
list 去重的方法：
1、转成 set 注意 set 无序
2、使用 dict.fromkeys(nums) 保留顺序 
nums = [1,1,1,1,2,2,2,3,3,5,5]
print(list(dict.fromkeys(nums)))

3、列表推导式 + set 保证有序 set.add() 天然返回 None
nums = [1,1,1,1,2,2,2,3,3,5,5,7,9]
seen = set()
result = [x for x in nums if not (x in seen or seen.add(x))]
print(result)

'''


def thirdMax(self, nums):

        ## 去重 + 排序
        seen = set()
        nums = [x for x in nums if not (x in seen or seen.add(x))]
        nums.sort()
        nums.reverse()
        
        ## [1,1,2] 去重排序后 nums[2] 数组越界
        if len(nums) < 3:
            return max(nums)


        return nums[2]